<div id="main-content">
  <div class="container-fluid">
    <div class="row-fluid">
			<div class="span12">
				<div class="nonboxy-widget">
					<div class="widget-head">
						<h5><i class="black-icons blocks_images"></i><?php print $title?></h5>
					</div>
					<div class="widget-content">
						<div class="widget-box">
              <?php print $this->form_eksternal->form_open_multipart("", 'class=" form-horizontal well" id="formoutlet"', 
                      array("id_detail" => $detail[0]->id_crm_products))?>
								<fieldset width='45%' style='float: left'>
									<div class="control-group">
										<label class="control-label"><?php print lang("product_name")?></label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_input('title', $detail[0]->title, 'class="span4" style="width:100%"')?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label"><?php print lang("product_code")?></label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_input('code', $detail[0]->code, 'class="span4" style="width:100%"')?>
										</div>
									</div>
                  <div class="control-group">
										<label class="control-label"><?php print lang("product_picture")?></label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_upload('picture', $detail[0]->picture, 'class="span4" style="width:100%"')?>
                      <?php
                      if($detail[0]->picture)
                        print "<br /><img src='".base_url()."files/crm/products/50/{$detail[0]->picture}' />";
                      else
                        print "<br /><img src='".base_url()."files/no-pic.png' width='50' />";
                      ?>
										</div>
									</div>
                  <div class="control-group">
										<label class="control-label"><?php print lang("product_category")?></label>
										<div class="controls">
											<select name="id_crm_product_category" data-placeholder="Product Category" style=" width:300px" class="chzn-select" tabindex="13">
                        <?php
                        foreach ($parent as $id_parent => $category){
                          print "<optgroup label='{$category}'>";
                          $child = $this->global_models->get("crm_product_category", array("id_parent" => $id_parent));
                          foreach($child as $c_category){
                            print "<option value='{$c_category->id_crm_product_category}'>{$c_category->name}</option>";
                          }
                          print "</optgroup>";
                        }
                        ?>
											</select>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label"><?php print lang("product_brand")?></label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_dropdown('id_crm_product_brand', $brand, $detail[0]->id_crm_product_brand, '')?>
										</div>
									</div>
								</fieldset>
								<fieldset width='45%' >
                  <div class="control-group">
										<label class="control-label"><?php print lang("product_weight")?></label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_input('weight', $detail[0]->weight, 'class="span4" id="weight"')?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label"><?php print lang("product_price")?></label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_input('price', $detail[0]->price, 'class="span4" id="price" onblur="harga_jual()"')?>
										</div>
									</div>
                  <div class="control-group">
										<label class="control-label"><?php print lang("product_discount")?></label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_input('discount', $detail[0]->discount, 'class="span1" id="discount" onblur="harga_jual()"')?> %
                      = Rp <span id="harga_jual"><?php print number_format($detail[0]->price - ($detail[0]->price * ($detail[0]->discount/100)), "0", ",", ".")?></span>
										</div>
									</div>
                  <div class="control-group">
										<label class="control-label"><?php print lang("note")?></label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_textarea('note', $detail[0]->note, 'class="span4" style="width:100%"')?>
										</div>
									</div>
								</fieldset>
                
								<div class="form-actions" style='width: 100%'>
									<button class="btn btn-primary" type="submit"><?php print lang("save")?></button>
									<button class="btn" onclick="history.go(-1);return false;"><?php print lang("cancel")?></button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
  </div>
</div>
<script>
  function harga_jual(){
    var price = $("#price").val() * 1;
    var discount = $("#discount").val() * 1;
    var affiliate = $("#affiliate").val() * 1;
    var discount_rp = price * (discount/100);
    var harga_jual = price - discount_rp;
    var harga_affiliate = harga_jual * (affiliate / 100);
    $("#harga_jual").text(get_dot(harga_jual, false));
    $("#harga_affiliate").text(get_dot(harga_affiliate, false));
    $("#pendapatan").text(get_dot((harga_jual - harga_affiliate), false));
  }
  function get_dot(asli, koma){
    asli = asli.toFixed(0);
    asli = asli.toString();
    var asli_temp = asli.split(".");
    var string = asli_temp[0];
    var string_hasil = "";
    
    var tanda = 0;
    var kl = string.length % 3;
    if(kl == 0)
      kl = 3;
    for(i = 0 ; i < string.length ; i++){
      if(tanda == 3 || i == kl){
        string_hasil = string_hasil + ".";
        tanda = 0;
        kl = 0;
      }
      string_hasil = string_hasil + string[i];
      tanda++;
    }
//    if(koma == true){
      if(!asli_temp[1])
        asli_temp[1] = '';
      
      return string_hasil;
//    }
//    else
//      return string_hasil;
  }
</script>